package com.jdk8.demo.date;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * Java8的时间测试类
 */
public class Java8DateTest {
    public static void main(String[] args) {
        LocalDate now = LocalDate.now();
        System.out.println(LocalDate.of(2019,1,2));
        System.out.println(now);
        System.out.println(now.plusDays(-1));
        System.out.println(now.plusYears(-2));
        System.out.println(now.plusMonths(1));
        System.out.println(now.plusWeeks(1));
        System.out.println(now.plus(2, ChronoUnit.YEARS));
        // 减对应的天数,可以传负数
        System.out.println(now.minusDays(1));
        System.out.println(now.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));

        System.out.println("------------------------");

        LocalDate date1 = LocalDate.of(2019, 1, 12);
        LocalDate date2 = LocalDate.of(2019, 1, 13);

        System.out.println(date1.isAfter(date2));
        System.out.println(date1.isBefore(date2));
        System.out.println(date1.isEqual(date2));

        System.out.println("-------------------");

        LocalTime localTime = LocalTime.now();
        System.out.println(localTime);
        LocalTime time = LocalTime.of(10, 10, 10);
        System.out.println(time);
        LocalTime parse = LocalTime.parse("10:15:30");
        System.out.println(parse);

        System.out.println("---------------");
        LocalTime now1 = LocalTime.now();
        System.out.println(now1.getHour());
        System.out.println(now1.getMinute());
        System.out.println(now1.getSecond());

        System.out.println("----------------------");
        System.out.println(now1.withHour(1));
        System.out.println(now1.withMinute(1));
        System.out.println(now1.withSecond(1));

        LocalTime localTime1 = LocalTime.parse("13|35|23",DateTimeFormatter.ofPattern("HH|mm|ss"));
        System.out.println(localTime1);


    }
}